package com.jincp.common.http;

import android.content.Context;

import com.jincp.common.http.okhttp.OkHttpProcessor;

/**
 * =========================================================
 * @ProjectName: 网络请求类
 * @ClassName: HttpProcessor
 * @Description:
 * @Author: jincp
 * @CreateDate: 2019/9/3 09:40
 * =========================================================
 */
public class HttpProcessor implements IHttpProcessor {

    public static final int DEFAULT_CONNECT_TIMEOUT = 20 * 1000;
    public static final int DEFAULT_READ_TIMEOUT = 20 * 1000;
    public static final int DEFAULT_WRITE_TIMEOUT = 20 * 1000;

    public static final int ERROR_FROM_NETWORK = 1;
    public static final int ERROR_FROM_SERVER = 2;
    public static final int ERROR_FROM_PARSER = 3;


    private static HttpProcessor instance;

    private static IHttpProcessor iHttpProcessor = null;

    private HttpProcessor() {
        iHttpProcessor = new OkHttpProcessor();
    }

    public static HttpProcessor getInstance() {
        if (instance == null) {
            synchronized (HttpProcessor.class) {
                if (instance == null) {
                    instance = new HttpProcessor();
                }
            }
        }
        return instance;
    }

    @Override
    public void init(Context context) {
        iHttpProcessor.init(context);
    }

    @Override
    public void post(Object tag, String url, boolean isProgress, HttpRequestParams params, IHttpCallback callback) {
        iHttpProcessor.post(tag, url, isProgress, params, callback);
    }

    @Override
    public void get(Object tag, String url, boolean isProgress, HttpRequestParams params, IHttpCallback callback) {
        iHttpProcessor.get(tag, url, isProgress, params, callback);
    }

    @Override
    public void cancelRequest(Object tag) {
        iHttpProcessor.cancelRequest(tag);
    }
}
